<?= $this->Html->css('multi-inputs', null, array('inline'=>false)) ?>
<?= $this->Html->script('multi-inputs.asset', array('inline'=>false)) ?>

<p class="entity-table">
    <?= $this->Html->link("&laquo; nazad", "/offers", array( 'escape' => false ))?>
    
    <span class="actions visible form button-set">
    <? if (!empty($data['Offer']['id'])): ?>
    <? $offerId = $data['Offer']['id'] ?>
    
        <?= $this->Form->button('Štampaj', array(
            'type'    => 'button',
            'onclick' => "pdfPonuda({$offerId})"
        )) ?><?= $this->Form->button('Obriši', array(
            'class'   => 'delete',
            'onclick' => "if (confirm('Da li želite da obrišete ponudu?')){location.href = '/offers/remove/{$offerId}'}"
        ))?>
    <? endif ?>
    </span>
</p>


<?= $this->Form->create('Offer', array('url' => '/offers/save')) ?>

    <?= $this->Form->hidden('id', array( 'value' => (int)@$data['Offer']['id'])) ?>

    <p><?= $this->Form->label('client_id', 'Klijent:') ?>
    <?= $this->Form->select('client_id', $clients, array(
        'value' => @$data['Client']['id'],
        'empty' => false
    )) ?></p>
    
    <p class="left"><?= $this->Form->label('OffersLocation.location_id.', 'Lokacije:', array('class'=>'left')) ?>
    <? if (empty($data['OffersLocation'])) {
        $data['OffersLocation'][] = array(
            'id'         => 0,
            'start'      => '',
            'end'        => '',
            'production' => 1,
            'mount'      => 1
        );
    } ?>
    
    <span class="multi-inputs left">
        <? foreach ($data['OffersLocation'] as $k=>$offers_location): ?>
        <span class="multi-input">
            <?= $this->Form->hidden("OffersLocation.{$k}.id", array( 'value' => $offers_location['id'])) ?>
            <?= $this->Form->select("OffersLocation.{$k}.location_id", $locations, array(
                'value' => @$offers_location['location_id'],
                'empty' => false
            )) ?>
            
            <?= $this->Form->label("OffersLocation.{$k}.start", 'Period zakupa:', array('class'=>'auto')) ?>
            <?= $this->Form->text("OffersLocation.{$k}.start", array(
                'value' => $offers_location['start'],
                'class' => 'datepicker',
                'required' => false
            )) ?> - 
            <?= $this->Form->text("OffersLocation.{$k}.end", array(
                'value' => $offers_location['end'],
                'class' => 'datepicker',
                'required' => false
            )) ?>
            
            <?= $this->Form->label("OffersLocation.{$k}.discount", "Popust:", array('class'=>'auto')) ?>
            <?= $this->Form->text("OffersLocation.{$k}.discount", array(
                'value' => @$offers_location['discount'],
                'class' => 'number'
            )) ?> %
            
            <?= $this->element('production_picker', array(
                'name'  => "OffersLocation.{$k}.production",
                'value' => $offers_location['production'],
                'label' => $this->Form->label("OffersLocation.{$k}.production", 'Produkcija:', array(
                    'class'=>'auto'
                ))
            )) ?>
        </span>
        <? endforeach ?>
    </span></p>
    
    <p class="clear"><?= $this->Form->label('campaign_id', 'Kampanja:') ?>
    <?= $this->App->autocomplete('campaign_id', array(
        'label'  => @$data['Campaign']['label'],
        'value'  => @$data['Campaign']['id'],
        'url' => '/campaigns/search'
    )) ?></p>
    
    <?= $this->Form->button('Sačuvaj') ?>
<?= $this->Form->end() ?>
